import { saveAndEditerCategoryNode, mappingKnowledgeDomainDetail,removeCategory ,editerCategoryNode} from '@/services/knowledgegraph';

export default {
  namespace: 'knowledgeGraphEdit',
  state: {
    total: null,
    data: [],
    loading: false,
  },

  effects: {
    *saveAndEditerNode({ payload, callback }, { call, put }) {
      const response = yield call(saveAndEditerCategoryNode, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *getGraphDetail({ payload, callback }, { call, put }) {
      const response = yield call(mappingKnowledgeDomainDetail, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *removeCategoryNode({ payload, callback }, { call, put }) {
      const response = yield call(removeCategory, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *editerCategory({ payload, callback }, { call, put }) {
      const response = yield call(editerCategoryNode, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
